OUTFILE := program.exe
# Comment out the frameworks contents for non-Mac builds
FRAMEWORKS := -framework OpenGL -framework AGL -framework Carbon
LDFLAGS := -lpthread -lglfw -lftgl
#  -Wshadow -Weffc++
CPPFLAGS := -Wall -W -Woverloaded-virtual -Wnon-virtual-dtor -Wdeprecated -Wcast-qual -Wpointer-arith  -g -m32
COLORFILT := #| ./color_filt
BUILD_DIR := build

OBJS := $(patsubst ./%.cpp, $(BUILD_DIR)/%.o, $(shell find . -name "*.cpp" \( ! -name "._*" \)))
TEMPS := $(shell find . -name "*~")

DEPENDS:=$(OBJS:.o=.d)

all: $(OBJS)
	@echo "Linking...";
	@g++ $(OBJS) $(CPPFLAGS) $(LDFLAGS) $(FRAMEWORKS) -o $(OUTFILE)
	@echo "DONE!"

ifeq ($(findstring clean,$(MAKECMDGOALS)),)
-include $(DEPENDS)
endif

%.o:
	@mkdir -p $(dir $@)
	@src=$(patsubst %.o,%.cpp,$(patsubst $(BUILD_DIR)/%,%,$@)); \
	echo "Compiling $$src"; \
	g++ $(CPPFLAGS) -o $@ -c $$src 2>&1 $(COLORFILT)
	
%.d:
	@mkdir -p $(dir $@)
	@src=$(patsubst %.d,%.cpp,$(patsubst $(BUILD_DIR)/%,%,$@)); \
	echo "$@..." | sed 's@.*.d/@Generating @'; \
	g++ $(CPPFLAGS) -MP -MG -MT "$@" -MT "$(@:.d=.o)" -MM "$$src" > $@
	
%.h :
	@echo "Could not find header file $@, you will need fix the header(s) and then 'make cleanDeps'"
	@false

cleanDeps:
	@rm $(DEPENDS)

clean:
	rm -rf $(OBJS) $(DEPENDS) $(TEMPS) $(OUTFILE) $(BUILD_DIR)
	
